import FileSaver from 'file-saver'
import * as XLSX from 'xlsx'
import { MessageBox } from 'element-ui';
export  function toXlsx(ele,fileName,filter){
    MessageBox.confirm("是否确认导出当前表格数据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((response) => {
            var fix = document.querySelector('.el-table__fixed-right');
            var wb;
            if (fix) {
              wb = XLSX.utils.table_to_book(document.querySelector(ele).removeChild(fix));
              document.querySelector(ele).appendChild(fix);
            } else {
              wb = XLSX.utils.table_to_book(document.querySelector(ele));
            }
          for (let key in wb.Sheets.Sheet1){
            console.log(wb.Sheets.Sheet1[key])
            if (wb.Sheets.Sheet1[key].v === '操作'||wb.Sheets.Sheet1[key].v==='编辑删除') {
                delete wb.Sheets.Sheet1[key];
            }
          }
          var wbout = XLSX.write(wb, {
            bookType: "xlsx",
            bookSST: true,
            type: "array",
          });
          try {
            FileSaver.saveAs(
              new Blob([wbout], { type: "application/octet-stream" }),
              `${fileName}.xlsx`
            );
          } catch (e) {
            if (typeof console !== "undefined") console.log(e, wbout);
          }
          return wbout;
        });
}